xl: Return void from libxl_free() and libxl_free_all()
author"Gianni Tedesco (3P)" <gianni.tedesco@citrix.com>
Wed, 11 Aug 2010 12:01:47 +0000 (13:01 +0100)
committer"Gianni Tedesco (3P)" <gianni.tedesco@citrix.com>
Wed, 11 Aug 2010 12:01:47 +0000 (13:01 +0100)
Also abort() if a pointer passed in to libxl_free() cannot be found in the
mini-gc structures. This exposes several real bugs (ie. not just the
libxl_free() something that was allocated via malloc variety).

Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
tools/libxl/libxl_internal.c
tools/libxl/libxl_internal.h

index a0179b4e46420890d050c4dc988105d43ab1e4b7..22595f1578e5309ab38cdb923c2530df7aab1599 100644 (file)
@@ -59,26 +59,26 @@ int libxl_ptr_add(libxl_ctx *ctx, void *ptr)
     return 0;
 }
 
-int libxl_free(libxl_ctx *ctx, void *ptr)
+void libxl_free(libxl_ctx *ctx, void *ptr)
 {
     int i;
 
     if (!ptr)
-        return 0;
+        return;
 
     /* remove the pointer from the tracked ptrs */
     for (i = 0; i < ctx->alloc_maxsize; i++) {
         if (ctx->alloc_ptrs[i] == ptr) {
             ctx->alloc_ptrs[i] = NULL;
             free(ptr);
-            return 0;
+            return;
         }
     }
     /* haven't find the pointer, really bad */
-    return -1;
+    abort();
 }
 
-int libxl_free_all(libxl_ctx *ctx)
+void libxl_free_all(libxl_ctx *ctx)
 {
     void *ptr;
     int i;
@@ -88,7 +88,6 @@ int libxl_free_all(libxl_ctx *ctx)
         ctx->alloc_ptrs[i] = NULL;
         free(ptr);
     }
-    return 0;
 }
 
 void *libxl_zalloc(libxl_ctx *ctx, int bytes)
index dde37df1aa2127942d78780f357f021aa5e29f60..401f812ff7f4d03fc78fa5c719a655bdad7b71cd 100644 (file)
@@ -108,8 +108,8 @@ int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[])
 
 /* memory allocation tracking/helpers */
 int libxl_ptr_add(libxl_ctx *ctx, void *ptr);
-int libxl_free(libxl_ctx *ctx, void *ptr);
-int libxl_free_all(libxl_ctx *ctx);
+void libxl_free(libxl_ctx *ctx, void *ptr);
+void libxl_free_all(libxl_ctx *ctx);
 void *libxl_zalloc(libxl_ctx *ctx, int bytes);
 void *libxl_calloc(libxl_ctx *ctx, size_t nmemb, size_t size);
 char *libxl_sprintf(libxl_ctx *ctx, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);